var app = getApp()
var pageData = {
    data: {
      phone: '',
      password:''
    },
   
  // 获取输入账号
    phoneInput :function (e) {
      this.setData({
        phone:e.detail.value
      })
    },
   
  // 获取输入密码
    passwordInput :function (e) {
      this.setData({
        password:e.detail.value
      })
    },

register: function () {
  if(this.data.phone.length == 0 || this.data.password.length == 0){
    app.showLoading("输入框不能为空")
    return
  }
  var _this = this;
  wx.request({ 
    url: app.globalData.user_register_url,
    data: {
      username:this.data.phone,
      password:this.data.password
    },
    method: 'POST', 
    success: function (res) {
      var resultData = res.data;
        if(resultData.errno == 0){  
          wx.setStorageSync("LOGINUSER_ID", resultData.data.id + "");
          app.showSuccess(resultData.message) 
          wx.switchTab({
            url: '../doctor-list/doctor-list'
          })
        }else{
          app.showModel("注册提示",resultData.message);
        }
    },
    fail: function () {
      setTimeout(function () {
        wx.showToast({
          title: "加载失败"
        })
      }, 100)
    }
  }) 
},   
  // 登录
login: function () {
  if(this.data.phone.length == 0 || this.data.password.length == 0){ 
    app.showLoading("输入框不能为空")
    return
  } 
    var _this = this;
      wx.request({ 
        url: app.globalData.user_login_url,
        data: {
          username:this.data.phone,
          password:this.data.password
        },
        method: 'POST', 
        success: function (res) {
          var resultData = res.data;
            if(resultData.errno == 0){  
              wx.setStorageSync("LOGINUSER_ID", resultData.data.id + ""); 
              app.showSuccess(resultData.message) 
              wx.switchTab({
                url: '../doctor-list/doctor-list'
              })
            }else{
              app.showModel("登录提示","用户名或密码错误");
            }
        },
        fail: function () {
          setTimeout(function () {
            wx.showToast({
              title: "加载失败"
            })
          }, 100)
        }
      })
    }  
  } 

Page(pageData);
